<!-- 编辑弹窗 -->
<template>
  <el-dialog
    title='录入回收补差金额'
    :visible="visible"
    width="960px"
    :destroy-on-close="true"
    :lock-scroll="false"
    @update:visible="updateVisible"
    @open="loadBalanceAmount">
    <ele-pro-table
      ref="table"
      :datasource="balanceAmountList"
      :columns="columns"
      :toolbar="false"
      :need-page="false"
      height="calc(100vh - 345px)">
      <template slot="bcje" slot-scope="{row}">
        <el-input v-model="row.balanceamount"></el-input>
      </template>
    </ele-pro-table>
    <div slot="footer">
      <el-button @click="updateVisible(false)">取消</el-button>
      <el-button
        type="primary"
        @click="save"
        :loading="loading">保存
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'BalanceAmountEdit',
  props: {
    // 弹窗是否打开
    visible: Boolean,
    // 修改回显的数据
    pid: Number
  },
  data() {
    return {
      // 表格列配置
      columns: [
        {
          columnKey: 'index',
          type: 'index',
          label: '序号',
          width: 45,
          align: 'center',
          fixed: "left"
        },
        {
          prop: 'invcode',
          label: '药品编码',
          showOverflowTooltip: true,
          minWidth: 80,
          align: 'center'
        },
        {
          prop: 'invname',
          label: '药品名称',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'left'
        },
        {
          prop: 'gg',
          label: '规格',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'left'
        },
        {
          prop: 'materialunit',
          label: '单位',
          showOverflowTooltip: true,
          minWidth: 50,
          align: 'left'
        },
        {
          prop: 'vmanufacturer',
          label: '生产厂家',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'left'
        },
        {
          prop: 'cgy',
          label: '采购员',
          showOverflowTooltip: true,
          minWidth: 80,
          align: 'left'
        },
        {
          prop: 'balanceamountapply',
          label: '申请金额',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'left'
        },
        {
          prop: 'balanceamountback',
          label: '回收金额',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'left',
          slot: 'bcje'
        },
        
      ],
      // 提交状态
      loading: false,
      balanceAmountList:[]
    };
  },
  methods: {
    /* 保存编辑 */
    save() {
        this.loading = true;
        this.$http.post('/spbcinvsetdetail/savebalanceamount', this.balanceAmountList).then(res => {
          this.loading = false;
          if (res.data.code === 0) {
            this.$message.success(res.data.msg);
            this.updateVisible(false);
          } else {
            this.$message.error(res.data.msg);
          }
        }).catch(e => {
          this.loading = false;
          this.$message.error(e.message);
        });     
    },
    /* 更新visible */
    updateVisible(value) {
      this.$emit('update:visible', value);
    },
    loadBalanceAmount(){
      if (this.pid) {
        let param = {
          pid:this.pid,
          page:1,
          limit:1000

        };
        this.$http.get('/spbcinvset/invsetdetail',{params:param}).then(res=>{
          if(res.status==200)
          {
            this.balanceAmountList = res.data.data.records;
          }
        });
      }
    }
  }
}
</script>

<style scoped>
</style>
